﻿using System;
using System.Collections.Generic;
using System.Text;
using EnvDTE;
using VSAddinLibrary.Utils;
using VSAddinLibrary.Attributes;

namespace VSAddinLibrary.Controllers
{
  public class BaseVSCommand : IVSCommand
  {
    public BaseVSCommand()
    {
      _commandName = string.Empty;
      _caption = string.Empty;
      _tooltip = string.Empty;
      _iconPath = string.Empty;
      loadDeclariveAttributes();
    }

    private void loadDeclariveAttributes()
    {
      Type type = this.GetType();

      VSCommandDeclarationAttribute vsCmdDeclarationAtt = AddinReflector.GetAttrib<VSCommandDeclarationAttribute>(type);
      if (vsCmdDeclarationAtt != null)
      {
        _commandName = vsCmdDeclarationAtt.CommandName;
      }

      VSCommandCaptionAttribute vsCmdCaptionAtt = AddinReflector.GetAttrib<VSCommandCaptionAttribute>(type);
      if (vsCmdCaptionAtt != null)
      {
        _caption = vsCmdCaptionAtt.Caption;
      }

      VSCommandToolTipAttribute vsCmdToolTipAtt = AddinReflector.GetAttrib<VSCommandToolTipAttribute>(type);
      if (vsCmdToolTipAtt != null)
      {
        _tooltip = vsCmdToolTipAtt.ToolTip;
      }
    }

    #region IVSCommand Members

    public virtual void QueryStatus(vsCommandStatusTextWanted NeededText, ref vsCommandStatus StatusOption, ref object CommandText)
    {

    }

    public virtual void Exec(vsCommandExecOption ExecuteOption, ref object VariantIn, ref object VariantOut, ref bool Handled)
    {

    }

    private EnvDTE.Command _command;
    public EnvDTE.Command Command
    {
      get { return _command; }
      set { _command = value; }
    }

    private string _commandName;
    public string CommandName
    {
      get { return _commandName; }
    }

    private string _tooltip;
    public virtual string ToolTip
    {
      get { return _tooltip; }
    }

    private string _caption;
    public virtual string Caption
    {
      get { return _caption; }
    }

    private string _iconPath;
    public virtual string IconPath
    {
      get { return _iconPath; }
    }

    #endregion
  }
}
